package edu.sias.controller;

import edu.sias.pojo.Post;
import edu.sias.service.SearchService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Service;
import java.io.IOException;
import java.util.List;

//控制层
@WebServlet(name = "SearchServlet")
public class SearchServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");

        response.setContentType("text/html;charset=UTF-8");

        String keyMsg =request.getParameter("keyMsg");
        System.out.printf("keyMsg="+keyMsg);

        SearchService searchService = new SearchService();

        List<Post> posts = searchService.getMsgInfo(keyMsg);

//返回数据给用户

        request.setAttribute("posts",posts);

//转发到showMsg，同时数据在request中

        request.getRequestDispatcher("showMsg.jsp").forward(request,response);

    }

}


